1 module dlangui_bearlibterminal.platform; 2 3 import dlangui; 4 import dlangui.platforms.common.platform; 5 6 class BearLibPlatform : Platform 7 { 8 import dlangui_bearlibterminal.window: BearLibWindow; 9 import BearLibTerminal: BT = terminal; 10 11 private BearLibWindow window; 12 13 // In BT ecosystem keycode contains any type of event 14 private bool dispatchBTEventToDlangui(in BT.keycode event) 15 { 16 import core.bitop: btr; 17 import dlangui_bearlibterminal.events; 18 19 const bool keyReleased = btr(cast(size_t*) &event, 8) != 0; 20 21 bool eventCatched; 22 23 { 24 auto ke = convertKeyEvent(event, keyReleased); 25 if(ke !is null) 26 eventCatched = window.dispatchKeyEvent(ke); 27 } 28 29 { 30 auto me = convertMouseEvent(event, keyReleased); 31 if(me !is null) 32 eventCatched = window.dispatchMouseEvent(me); 33 } 34 35 return eventCatched; 36 } 37 38 override: 39 40 BearLibWindow createWindow(dstring windowCaption, Window parent, uint flags, uint width, uint height) 41 { 42 assert(window is null); 43 44 window = new BearLibWindow(windowCaption); 45 46 return window; 47 } 48 49 void closeWindow(Window w) 50 { 51 assert(w == window); 52 assert(window !is null); 53 54 w.close(); 55 destroy(w); 56 57 window = null; 58 } 59 60 /** 61 * Starts application message loop. 62 * 63 * When returned from this method, application is shutting down. 64 */ 65 int enterMessageLoop() 66 { 67 do 68 { 69 auto event = BT.read(); 70 71 Log.v("MessageLoop event = "~event.to!string); 72 73 with(BT) 74 switch(event) 75 { 76 case keycode.close: 77 destroy(window); 78 Log.d("return 0"); 79 return 0; 80 81 case keycode.resized: 82 window.updateDlanguiWindowSize(); 83 window.invalidate(); 84 break; 85 86 default: 87 if(dispatchBTEventToDlangui(event)) 88 window.invalidate(); 89 90 break; 91 } 92 93 if(BT.has_input == 0) 94 window.redrawIfNeed(); 95 } 96 while(true); 97 } 98 99 dstring getClipboardText(bool mouseBuffer) 100 { 101 assert(false, "Isn't implemented"); 102 } 103 104 void setClipboardText(dstring text, bool mouseBuffer) 105 { 106 assert(false, "Isn't implemented"); 107 } 108 109 void requestLayout() 110 { 111 if(window !is null) 112 window.requestLayout(); 113 } 114 115 bool hasClipboardText(bool mouseBuffer) 116 { 117 assert(false, "Isn't implemented"); 118 } 119 }